package com.showde.shoppingmall.netentity;

import android.util.Log;

import com.kim.net.NetEntity;
import com.showde.shoppingmall.ShoppingMallApplication;
import com.showde.shoppingmall.utils.URLS;

public class AddressEntity extends NetEntity {

	private static final String TAG = "AddressEntity";

	/**
	 * 
	 */
	private static final long serialVersionUID = 9150037906821010515L;

	public enum OPERATION_TYPE {
		/**
		 * 增加收件人地址
		 */
		add,
		/**
		 * 获取收件人地址
		 */
		get,
		/**
		 * 修改收件人地址
		 */
		update,
		/**
		 * 删除收件人地址
		 */
		delete
	}

	private String recipientName; // 收件人姓名
	private String recipientAddress; // 收件人地址
	private String recipientMobile; // 收件人手机号
	private String recipientPostCode; // 收件人邮编

	private String recipientAddressId; // 收件人地址id

	private OPERATION_TYPE operation_type = OPERATION_TYPE.add; // 操作类型

	public AddressEntity() {
		operation_type = OPERATION_TYPE.get;
		url = URLS.URL_QUERY_ADDRESS;
	}

	/**
	 * 删除收件地址
	 * 
	 * @param addressId
	 */
	public AddressEntity(String addressId) {
		recipientAddressId = addressId;
		operation_type = OPERATION_TYPE.delete;
		url = URLS.URL_DELETE_ADDRESS;
	}

	public AddressEntity(String recipientName, String recipientAddress,
			String recipientMobile, String recipientPostCode) {
		this.recipientName = recipientName;
		this.recipientAddress = recipientAddress;
		this.recipientMobile = recipientMobile;
		this.recipientPostCode = recipientPostCode;
		operation_type = OPERATION_TYPE.add;
	}

	public AddressEntity(String recipientName, String recipientAddress,
			String recipientMobile, String recipientPostCode,
			String recipientAddressId) {
		this.recipientName = recipientName;
		this.recipientAddress = recipientAddress;
		this.recipientMobile = recipientMobile;
		this.recipientPostCode = recipientPostCode;
		this.recipientAddressId = recipientAddressId;
		this.url = URLS.URL_UPDATE_ADDRESS;
		operation_type = OPERATION_TYPE.update;
	}

	@Override
	public String getSendData() {
		String userAccount = "";
		if (ShoppingMallApplication.getSessionUser() != null) {
			userAccount = ShoppingMallApplication.getSessionUser()
					.getUserAccount();
		}
		String sendData = null;
		switch (this.operation_type) {
		case add:
			sendData = "{\"userAccount\": \"" + userAccount + "\","
					+ "\"name\": \"" + recipientName + "\"," + "\"addr\": \""
					+ recipientAddress + "\"," + "\"mobile\": \""
					+ recipientMobile + "\"," + "\"postcode\": "
					+ recipientPostCode + "}";
			break;
		case get:
			sendData = "{\"userAccount\":\"" + userAccount + "\"}";
			break;
		case update:
			sendData = "{\"userAccount\": \"" + userAccount + "\","
					+ "\"name\": \"" + recipientName + "\"," + "\"addr\": \""
					+ recipientAddress + "\"," + "\"mobile\": \""
					+ recipientMobile + "\"," + "\"postcode\": "
					+ recipientPostCode + ",\"id\":" + recipientAddressId + "}";
			break;
		case delete:
			sendData = "{\"Id\":" + recipientAddressId + "}";
			break;
		}

		Log.d(TAG, "sendData:" + sendData);
		return sendData;
	}

	@Override
	protected void init() {
		this.url = URLS.URL_ADD_ADDRESS;
	}

	@Override
	protected void initHttpHeader() {

	}

}
